﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using Acaweb.Common;
using Acaweb.Model.Entities;
using Acaweb.Model.Entities.DatosCompuestos;
using System.ServiceModel.Activation;
using Components = Acaweb.Componentes.Contracts;

namespace Acaweb.Servicios.Services
{
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
    public class CursosService : Contracts.ICursosService
    {
        Components.ICursosService _CursoComponent = AppCtx.Resolve<Components.ICursosService>();

        public List<Cursos> GetAll()
        {
            List<Model.Entities.Cursos> Lista = _CursoComponent.GetByPeriodoAcademico(new PeriodoAcademico
            {
                Ano = 2010,
                Periodo = 2
            }).ToList();
            return Lista;
        }

        public Cursos GetById(CursoPk Id)
        {
            return _CursoComponent.GetById(Id);
        }

        public List<Cursos> GetByPeriodoAcademico(PeriodoAcademico PeriodoAcademico)
        {
            return _CursoComponent.GetByPeriodoAcademico(PeriodoAcademico).ToList();
        }

        public List<Cursos> GetByPeriodoAcademicoAndPlanEstudio(PeriodoAcademico PeriodoAcademico, int CodigoPlan)
        {
            return _CursoComponent.GetByPeriodoAcademico(CodigoPlan, PeriodoAcademico).ToList();
        }

        public List<Cursos> GetByEstudianteAndPeriodoAcademico(PeriodoAcademico PeriodoAcademico)
        {
            return _CursoComponent.GetByEstudianteAndPeriodoAcademico(AuthenticationService.GetCurrent().ToInt(), PeriodoAcademico).ToList();
        }

        public List<Cursos> GetByDocente()
        {
            return _CursoComponent.GetByDocenteAndPeridoAcademico(AuthenticationService.GetCurrent().Username).ToList();
        }

        public List<Cursos> GetByMateria(int Materia)
        {
            Acaweb.Componentes.Contracts.IEstudiantesService _EstudianteComponent = AppCtx.Resolve<Acaweb.Componentes.Contracts.IEstudiantesService>();
            PeriodoAcademico PeriodoAcademico = _EstudianteComponent.GetLastPeriodoAcademico(AuthenticationService.GetCurrent().ToInt());

            return _CursoComponent.GetByMateria(Materia, PeriodoAcademico).ToList();
        }

        public List<Cursos> CargarPrematricula(PeriodoAcademico PeriodoAcademico)
        {
            return _CursoComponent.CargarPrematricula(int.Parse(AuthenticationService.GetCurrent().Username), PeriodoAcademico).ToList();
        }
    }
}